﻿
@{
    ViewBag.Title = "BrrNowView";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}

<table id="Insiders_BrrNowView_grid" class="easyui-datagrid" style="width:100%;" title="正在浏览的档案" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#Insiders_BrrNowView_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="Insiders_BrrNowView_tb" style="padding:2px 5px;">
    <input type="text" class="easyui-textbox" label="借阅人:" labelwidth="50px" style="width:180px" id="Insiders_BrrNowView_txtName" />
    <input type="text" class="easyui-textbox" label="借阅档号:" labelwidth="70px" style="width:180px" id="Insiders_BrrNowView_txtDH" />
    <select id="Insiders_BrrNowView_cmbType" class="easyui-combobox" labelposition="right" label="档案类型：" data-options="editable:false" name="Insiders_BrrNowView_cmbType" style="width:170px;" panelHeight="auto" editable="false">
        <option value="-1" selected="selected">全部</option>
        <option value="1">电子借阅</option>
        <option value="2">纸质借阅</option>
    </select>
    <a href="javascript:void(0);" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="QUERY()" style="height: 30px;width:100px">查询</a>
    <a href="javascript:void(0);" id="Insiders_BrrNowView_btnYQ" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="YQ()" style="width:110px;height:30px;">逾期催还</a>
</div>
<script>
    $(document).ready(function () {
        var type = $('#Insiders_BrrNowView_cmbType').combobox('getValue');
        $('#Insiders_BrrNowView_grid').datagrid({
            url: '/Insiders/Get_ajaxBrrNowViewArchive?brrstatus=' + '@ViewBag.BrrStatus' + '&type=' + type,
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation();
    });

   

    function SearchPager(num, size) {

        $('#Insiders_BrrNowView_grid').datagrid('options').url = '/Insiders/Get_ajaxBrrNowViewArchivePager?num=' + num +
            '&size=' + size;
        $('#Insiders_BrrNowView_grid').datagrid('reload');
        $('#Insiders_BrrNowView_grid').datagrid('options').pageNumber = num;
        $('#Insiders_BrrNowView_grid').datagrid('options').pageSize = size;
    }


    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#Insiders_BrrNowView_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                SearchPager(pageNumber, pageSize);
            }
        });
    }
    function QUERY() {
        var name = $('#Insiders_BrrNowView_txtName').val();
        var dh = $('#Insiders_BrrNowView_txtDH').val();
        var type = $('#Insiders_BrrNowView_cmbType').combobox('getValue');
        $('#Insiders_BrrNowView_grid').datagrid('options').url = '/Insiders/Get_ajaxBrrNowViewArchive?brrstatus='+'@ViewBag.BrrStatus'+'&type=' + type + '&name=' + name + '&dh=' + dh;
        $('#Insiders_BrrNowView_grid').datagrid('load');
    }
    function YQ()
    {
       // alert(1);
       // var rows = $('#Insiders_SPIndex_grid').datagrid('getChecked');
        var rows = $('#Insiders_BrrNowView_grid').datagrid('getChecked');
        if (rows.length == 0) {
            $.messager.alert('提示！', '请选择催还的对象!', 'info');
            return false;
        }
        else
        {
            //alert(2);
            var id = [];
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].BU_TYPE==1)
                {
                    $.messager.alert('提示！', '只有纸质借阅可以发送逾期邮件!', 'info');
                    return false;
                }
                else {
                    id.push(rows[i].BI_ID);
                }
            }
            $.ajax({
                url: "/Insiders/YQGHEmai",
                type: 'post',
                dataType: 'json',
                data: { 'id': id },
                success: function (data) {
                    $.messager.alert('提示', '完成催还', 'info');

                }
            });
        }
    }
    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
    function formatStatus(value, row) {
        if (value == 0) {
            return "申请";
        }
        else if (value == 1) {
            return "借出";
        }
        else {
            return "结束";
        }
    }
    function formatSPValue(value, row) {
        if (value == 0) {
            return "未审批";
        }
        else if (value == 1) {
            return "通过";
        }
        else {
            return "拒绝";
        }
    }
    function formatType(value, row) {
        if (value == 1) {
            return "电子借阅";
        }
        else  {
            return "纸质借阅";
        }
    }
    function formatYQTS(value, row) {
        if (value == 0) {
            return "";
        }
        else {
            return value;
        }
    }
    function formatEnd(value, row) {
        if (row.BU_TYPE == 1) {
            return "<a href='javascript:void(0)' onclick='END(" + value + ")'>结束</a>";
        }
        else
        {
            return "<a href='javascript:void(0)' onclick='INFO()'>结束</a>";
        }

    }
    function END(id)
    {
        $.ajax({
            url: "/Insiders/EndBrr",
            type: 'post',
            dataType: 'json',
            data: { 'id': id },
            success: function (data) {
                if (data = '1') {
                    $.messager.alert('提示', '结束借阅成功', 'info');
                }
                else {
                    $.messager.alert('提示', '结束借阅失败', 'info');
                }
            }
        });
    }
    function INFO()
    {
        $.messager.alert('提示', '只有电子借阅的档案才能提前结束', 'info');
    }
    function formatSPStatus(value, row) {
        if (value == 0) {
            return "未审批";
        }
        else if (value == 1) {
            return "已审批";
        }
        else if (value == 2) {
            return "流程中(本部门审批)";
        }
        else {
            return "流程中(归档部门审批)";
        }
    }
    function InitPagenation() {
        //设置分页控件
        var p = $('#Insiders_BrrNowView_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#Insiders_BrrNowView_grid').datagrid('options').url = '/Insiders/Get_ajaxBrrNowViewArchivePager?num=' + num + '&size=' + size;
        $('#Insiders_BrrNowView_grid').datagrid('reload');
        $('#Insiders_BrrNowView_grid').datagrid('options').pageNumber = num;
        $('#Insiders_BrrNowView_grid').datagrid('options').pageSize = size;
        return;
    }
</script>


